﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace aliyun_api_gateway_sdk
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //String bobyContent = "{\"vendor\": \"606272\", \"item\": [ { \"material\": \"80405361\",  \"availableQuantity\": \"12\",\"lockedQuantity\": \"3\",\" unit \": \"TAI\"  }  ]}";

            String path = "/MM/00882/VendorSynchronizeInventory";
          string cRe=  AliWeb.Post(GetBody(), path,"TEST");
            textBox1.Text = cRe;
        }

        /// <summary>
        /// 库存明细
        /// </summary>
        public class Item
        {
            /// <summary>
            /// 
            /// </summary>
            public string material { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string availableQuantity { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string lockedQuantity { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string unit { get; set; }
        }

        public class KuCun
        {
            /// <summary>
            /// 
            /// </summary>
            public string vendor { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public List<Item> item { get; set; }
        }

        public static string GetBody()
        {

            KuCun clsKuCun = new KuCun();
            clsKuCun.vendor = "606272";
            List<Item> items = new List<Item>();
            Item item = new Item();
            item.material = "80405361";
            item.availableQuantity = "100";
            item.lockedQuantity = "50";
            item.unit = "TAI";
            items.Add(item);
            clsKuCun.item = items;

            var jSetting = new JsonSerializerSettings();
            jSetting.NullValueHandling = NullValueHandling.Ignore;
            string json = JsonConvert.SerializeObject(clsKuCun, jSetting);
            return json;
        }
    }
}
